<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>换货</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>

    <div class="replacement" id="list">
        <div class="replacement-t mb20" id="order_number">订单号：123456789645312</div>
        <div class="replacement-m mb20">
            <h4>服务类型</h4>
            <ul>
                <li class="active">换货</li>
            </ul>
        </div>
        <div class="replacement-d">
            <h4>申请原因</h4>
            <ul id="reason">
                <li onclick="check_reason(1);"><label class="duihao"><i id="zhiliang"></i>质量问题</label></li>
                <li onclick="check_reason(2);"><label class="duihao"><i id="xiacuodan"></i>下错订单</label></li>
                <li onclick="check_reason(3);"><label class="duihao"><i id="gerenyuanyin"></i>个人原因</label></li>
            </ul>
        </div>
        <div class="replacement-text">
            <h4>问题描述</h4>
            <textarea name="" id="remark" placeholder="请详细描述问题"></textarea>
        </div>
    </div>

    <div class="btn-1 mt60" onclick="service_submit();">提交申请</div>
    
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">

    apiready = function(){
        order_id = api.pageParam.order_id;
        pay_number = api.pageParam.pay_number;
        $('#order_number').html('订单号: '+pay_number)
        $('#reason i').removeClass('active');
        $('#zhiliang').addClass('active');
        reason_type = 1;
    }
    
    // 选择原因
    function check_reason(type){
        if (type == 1) {
            $('#reason i').removeClass('active');
            $('#zhiliang').addClass('active');
            reason_type = 1;
        }else if(type == 2){
            $('#reason i').removeClass('active');
            $('#xiacuodan').addClass('active');
            reason_type = 2;
        }else{
            $('#reason i').removeClass('active');
            $('#gerenyuanyin').addClass('active');
            reason_type = 3;
        }
    }

    // 提交换货
    function service_submit(){

        var token = $api.getStorage('token');
        var remark = $api.byId('remark').value;
        api.ajax({
            url: webAddress + '/api/order/service',
            method: 'post',
            data: {
                values: {
                    order_id: order_id,
                    type: reason_type,
                    remark: remark,
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                if (ret.status_code == 200) {
                    api.toast({
                        msg: ret.message,
                        duration: 2000,
                        location: 'bottom',
                        global: true,
                    });
                    api.sendEvent({
                      name: 'reload'
                  });
                    api.closeToWin({
                        name: 'order'
                    });
                }
            } else {
                // alert( JSON.stringify( err ) );
                if(err.body.status_code == 400){
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });
    }

    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>